import { Item_base } from "./Item_base";
import Lable from "./Lable";
import Node from "./Node";

export default class Sprite implements Item_base{
    uuid: string = '1';
    name: string = 'Sprite';
    display: boolean = true;
    x: number = 0;
    y: number = 0;
    _x: number = 0;
    _y: number = 0;
    canvans: Node;
    child: any[] = []
    parent: any = undefined;


    width:number = 100;
    height:number = 100;
    path:string = '';
    constructor(canvans:Node){
        this.canvans = canvans;
    }
    addLable() {
        let item = new Lable(this.canvans);
        item.parent = this;
        this.child.push(item);
        return item;
    }
    addSprite() {
        let item = new Sprite(this.canvans);
        item.parent = this;
        this.child.push(item);
        return item;
    }
    /**
     * 默认全部使用png格式图片
     * @param fileName 图片路径名称
     */
    setPath(fileName:string){
        this.path = `${fileName}.png`;
    }
    draw(){
        this._x = this.x;
        this._y = this.y;
        let offsetX = 0;
        let offsetY = 0;
        if(this.parent){
            offsetX = this.parent._x;
            offsetY = this.parent._y;
        }
        this.canvans.render(offsetX,offsetY,[this]);
    }
}